<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class users extends CI_Controller {
	var $data;
	public function __construct()
	{
		parent::__construct();
		$this->load->library('session');
		$this->load->library('pagination');
		$this->load->library('fclass');
		$data['title'] = "Customer";
		$this->load->model('model_customer');
		$this->load->model('model_user');
		$this->load->model('model_feeds');
		$this->load->model('model_companies');
		// CHECK LOGIN
		$check = $this->session->userdata('login');
		if($check==false){
			redirect(base_url().'login/', 'refresh');
			return;
		}
	}

	public function index()
	{
		$this->load->view('users', $this->data);
	}

	public function detail(){
		$paging=@$_GET["per_page"];
		if($paging<0){
			$paging=0;
		}
		if(isset($_REQUEST['id'])&&$_REQUEST['id']!=""){
				$this->data["result_user"] = $this->model_user->selectDetailId(array('uId'=>$_REQUEST['id']));
				$this->data["result_feed"] = $this->model_feeds->select(array('feed_creator_id'=>$_REQUEST['id'],'limit'=>10,'paging'=>$paging));
				$this->data["result_feed_count"] = $this->model_feeds->selectCount(array('feed_creator_id'=>$_REQUEST['id']));
				$this->data["result_feed_date_count"] = $this->model_feeds->selectCount(array('feed_creator_id'=>$_REQUEST['id'],'feed_action_time'=>time()-108000));
				$this->data["result_feed_date"] = $this->model_feeds->select(array('feed_creator_id'=>$_REQUEST['id'],'feed_action_time'=>time()-8640,'limit'=>5,'paging'=>0));
				$this->data["count_customer"] = $this->model_customer->selectCountCust(array('cust_creator_id'=>$_REQUEST['id']));

				
				$this->data["set_page"] 	= 'user_detail';
				$this->load->view('users', $this->data);
		}else{
			$this->load->view('404');
		}

	}

	public function add(){
		$this->data["set_page"] = 'customer_add';
		$this->load->view('customer', $this->data);
	}
}

